<template>
  <div class="index-page">
    <a-input-search
      v-model:value="searchParams.text"
      placeholder="input search text"
      enter-button="Search"
      size="large"
      @search="onSearch"
    />
    <MyDivider />
    <a-tabs v-model:activeKey="activeKey" @change="onTabchange">
      <a-tab-pane key="post" tab="文章">
        <post-list :post-list="postList" />
      </a-tab-pane>
      <a-tab-pane key="picture" tab="图片">
        <picture-list />
      </a-tab-pane>
      <a-tab-pane key="user" tab="用户">
        <user-list :user-list="userList" />
      </a-tab-pane>
    </a-tabs>
  </div>
</template>

<script setup lang="ts">
import { ref, watchEffect } from "vue";
import PostList from "@/components/PostList.vue";
import PictureList from "@/components/PictureList.vue";
import UserList from "@/components/UserList.vue";
import MyDivider from "@/components/MyDivider.vue";
import { useRoute, useRouter } from "vue-router";
import MyAxios from "@/plugins/myAxios";
const router = useRouter();
const route = useRoute();
const postList = ref([]);
const userList = ref([]);
const activeKey = route.params.category;
MyAxios.post("/post/list/page/vo", {}).then((res: any) => {
  postList.value = res.data.data.records;
});
MyAxios.post("/user/list/page/vo", {}).then((res: any) => {
  userList.value = res.data.data.records;
});
const initSearchParams = {
  text: "",
  pageSize: 10,
  pageNum: 1,
};
const searchParams = ref(initSearchParams);

watchEffect(() => {
  searchParams.value = {
    ...initSearchParams,
    text: route.query.text as string,
  };
});
const onSearch = (value: string) => {
  router.push({
    query: searchParams.value,
  });
};
const onTabchange = (key: string) => {
  router.push({
    path: `/${key}`,
    query: searchParams.value,
  });
};
</script>

<style scoped>
.ant-list-item-meta-title {
  marin-top: 0px !important;
}
</style>
